/* $Id: AttachmentTypeDAOImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.dao.provider;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import ae.pcfc.etks.online.common.dao.AttachmentTypeDAO;
import ae.pcfc.etks.online.common.domain.AttachmentType;

@Repository
public class AttachmentTypeDAOImpl extends BaseDAO implements AttachmentTypeDAO{
	
	/**
	 * getAttachmentType
	 * $
	 * @param strAttachmentTypeUser
	 * @return
	 * @see ae.pcfc.etks.online.common.dao.AttachmentTypeDAO#getAttachmentType(java.lang.String)
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<AttachmentType> getAttachmentType(String strAttachmentTypeUser){
		
		Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(AttachmentType.class);
		
		if(strAttachmentTypeUser != null)
			criteria.add(Restrictions.eq("attachmentTypeUser", strAttachmentTypeUser));	
		
		criteria.addOrder( Order.asc("attachmentTypeDesc"));
		return criteria.list();		
	}

	/**
	 * getAttachmentTypeByAttachmentCode
	 * $
	 * @param attachmentCode
	 * @return
	 * @see ae.pcfc.etks.online.common.dao.AttachmentTypeDAO#getAttachmentTypeByAttachmentCode(java.lang.String)
	 * @return
	 */
	public AttachmentType getAttachmentTypeByAttachmentCode(String attachmentCode) {
		Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(AttachmentType.class);
		criteria.add(Restrictions.eq("attachmentTypeCode", attachmentCode));		
		@SuppressWarnings("unchecked")		
		List<AttachmentType> list =  criteria.list();
		
		if(list.size() > 0)
			return list.get(0);
		else
			return null;
	}
}
